package com.oceansoft.mobile.econsole.modules.weixin.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oceansoft.mobile.econsole.common.constant.Constant;
import com.oceansoft.mobile.econsole.common.util.web.PageUtil;
import com.oceansoft.mobile.econsole.modules.base.entity.Pager;
import com.oceansoft.mobile.econsole.modules.base.entity.Query;
import com.oceansoft.mobile.econsole.modules.base.entity.WxQuery;
import com.oceansoft.mobile.econsole.modules.weixin.dao.ICommonDao;
import com.oceansoft.mobile.econsole.modules.weixin.entity.Wxjq;
import com.oceansoft.mobile.econsole.modules.weixin.persistence.IApiWxjqMapper;
import com.oceansoft.mobile.econsole.modules.weixin.service.IApiWxjqService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ApiWxjqServiceImpl implements IApiWxjqService {
	@Resource
	private ICommonDao commonDao;

	@Resource
	private IApiWxjqMapper apiWxjqMapper;
	
	@Override
	public Pager<Wxjq> queryWxjq(String title, int pageindex) {
		WxQuery query = new WxQuery();
		query.setRows(Constant.PAGE_SIZE);
		query.setPage(pageindex);
		/*String page_sql = String.format(
				"SELECT t.* FROM t_wxjq t WHERE T.title like ? and T.url != '' %s  ",
				WxQuery.getPageSQL("T", query));
		String count_sql = String.format(
				"SELECT COUNT(*) FROM t_wxjq T WHERE T.title like ? and T.url != '' %s  ",
				WxQuery.getCountSQL("T", query));
		List<Wxjq> list = new ArrayList<Wxjq>();
		list = commonDao.loadList(page_sql, new WxjqMapper(),"%"+title+"%");
		int total = commonDao.getCount(count_sql,"%"+title+"%");*/


//		return new Pager<Wxjq>(total, query.getPage(), list);
		return null;
	}

	@Override
	public Pager<Wxjq> queryWxjq2(String title, int pageindex, String areaId) {
		Query query = new Query();
		query.setNumPerPage(Constant.API_PAGE_SIZE);
		query.setPageNum(pageindex);
		query.setTitle(title);
		query.setAreaId(areaId);
		/*String page_sql = String.format(
				"SELECT t.* FROM t_wxjq t WHERE T.area_id = ? and T.title like ? and T.url != '' %s  ",
				WxQuery.getPageSQL("T", query));
		String count_sql = String.format(
				"SELECT COUNT(*) FROM t_wxjq T WHERE T.area_id = ? and T.title like ? and T.url != '' %s  ",
				WxQuery.getCountSQL("T", query));
		List<Wxjq> list = new ArrayList<Wxjq>();
		list = commonDao.loadList(page_sql, new WxjqMapper(),areaId,"%"+title+"%");
		int total = commonDao.getCount(count_sql,areaId,"%"+title+"%");*/

		PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
		Page<Wxjq> page = (Page<Wxjq>) apiWxjqMapper.queryWxjqByPager(query);

		return PageUtil.page2pager(page, query);
	}

	@Override
	public List<Wxjq> getWxjqList(String title, String areaId,String type){
		return apiWxjqMapper.getWxjqList(title,areaId,type);
	}
	
}
